package com.kucai.yifaqapp.util;

import android.support.annotation.NonNull;
import android.util.Log;

import com.kucai.yifaqapp.model.network.HttpJsonUtils;

/**
 * 打印工具类
 */
public class SYSOUtils {
    private static final boolean PRINT = HttpJsonUtils.TEST;//开启打印标记
    private static final String TAG = "MyLog";//打印标签

    private SYSOUtils() {
    }

    public static void errLog(String exceptionInfo, Throwable throwable) {
        if (!PRINT) return;

        StackTraceElement stackTraceElement = Thread.currentThread().getStackTrace()[4];
        Log.e(TAG, ">----------------------------------------------------------------------------------------------------------------------------\n"
                + exceptionInfo + "\n"
                + stackTraceElement.getClassName() + "." + stackTraceElement.getMethodName() + "@Line:" + stackTraceElement.getLineNumber());
        throwable.printStackTrace();
        Log.e(TAG, "\n<============================================================================================================================");

    }

    public static void tagLog(String tag, @NonNull Object... str) {
        if (!PRINT || str == null) return;
        for (Object obj : str) {
            if (obj == null) {
                Log.w(TAG, "null");
                continue;
            }
            Log.d(tag, obj.toString());
        }
    }

    public static void sOut(@NonNull Object... str) {
        if (!PRINT || str == null) return;
        StackTraceElement stackTraceElement = Thread.currentThread().getStackTrace()[3];
        Log.e(TAG, ">----------------------------------------------------------------------------------------------------------------------------\n"
                + stackTraceElement.getClassName() + "." + stackTraceElement.getMethodName() + "@Line:" + stackTraceElement.getLineNumber());
        for (Object obj : str) {
            if (obj == null) {
                Log.w(TAG, "null");
                continue;
            }
            Log.w(TAG, obj.toString());
        }
        Log.e(TAG, "\n<============================================================================================================================");
    }

    public static void sOut_(@NonNull Object... str) {
        if (!PRINT || str == null) return;
        StackTraceElement stackTraceElement = Thread.currentThread().getStackTrace()[3];
        Log.e(TAG, ">++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n"
                + stackTraceElement.getClassName() + "." + stackTraceElement.getMethodName() + "@Line:" + stackTraceElement.getLineNumber());
        for (Object obj : str) {
            if (obj == null) {
                Log.w(TAG, "null");
                continue;
            }
            Log.w(TAG, obj.toString());
        }
        Log.e(TAG, "\n<****************************************************************************************************************************");
    }

    public static void simple(@NonNull Object... str) {
        if (!PRINT || str == null) return;
        for (Object obj : str) {
            if (obj == null) {
                Log.w(TAG, "null");
                continue;
            }
            Log.w(TAG, obj.toString());
        }
    }


//    public void  function ObjectToJson(object) {
//        // Object转换为josn
//        var json = "";
//
//        switch (jQuery.type(object)) {
//            case "array":
//                json = "[";
//
//                $.each(object, function (i, item) {
//                json += ObjectToJson(item) + ",";
//            });
//
//            if (json != "[" && json.length > 0) json = json.substr(0, json.length - 1);
//
//            json += "]";
//
//            break;
//
//            case "object":
//                json = "{";
//
//                $.each(object, function (key, value) {
//                if (jQuery.type(value) == "object") {
//                    json += "\"" + key + "\":" + ObjectToJson(value) + ",";
//                } else if (jQuery.type(value) == "array") {
//                    json += "\"" + key + "\":" + ObjectToJson(value) + ",";
//                } else {
//                    json += "\"" + key + "\":\"" + value + "\",";
//                }
//            });
//
//            if (json != "{" && json.length > 0) json = json.substr(0, json.length - 1);
//
//            json += "}";
//
//            break;
//
//            default:
//                json = "\"" + object + "\"";
//                break;
//        }
//
//        return json;
//    }


}
